package com.jp.knowledge.my.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.my.adapter.VieCoinHistoryAdapter;
import com.jp.knowledge.my.business.MyVieCoinBusiness;
import com.jp.knowledge.my.model.VieCoinHistoryModel;

import org.xutils.view.annotation.ViewInject;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 我的竟币
 *
 * @author gzejia 978862664@qq.com
 */
public class MyVieCoinActivity extends SlidingActivity implements View.OnClickListener {

    @ViewInject(R.id.vie_coin_rv_data)
    private RecyclerView mDataRv;

    @ViewInject(R.id.vie_coin_tv_number)
    private TextView mNumberTv;

    @ViewInject(R.id.vie_coin_tv_date)
    private TextView mDateTv;

    private MyVieCoinBusiness mBusiness = new MyVieCoinBusiness();

    @Override
    protected int getResourceId() {
        return R.layout.activity_my_vie_coin;
    }

    @Override
    protected void init() {
        initTitle();
        initDataRv(mBusiness.getVieCoinHistories());
        initOthers();
        initClickListener();
    }

    private void initClickListener(){
        leftIcon.setOnClickListener(this);
        findViewById(R.id.vie_coin_tv_how).setOnClickListener(this);
        findViewById(R.id.vie_coin_tv_shop).setOnClickListener(this);
        mDateTv.setOnClickListener(this);
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.icon_left:// 返回
                finish();
                break;
            case R.id.vie_coin_tv_how:// 如何赚币                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        +----------------------

                break;
            case R.id.vie_coin_tv_shop:// 竟币商城
                break;
            case R.id.vie_coin_tv_date:// 记录日期
                break;
        }
    }

    private void initTitle() {
        topName.setText(R.string.my_vie_coin_tv_main);
        topDesc.setVisibility(View.GONE);
        leftIcon.setImageResource(R.mipmap.arrow_white_left);
        rightIcon.setVisibility(View.GONE);
    }

    private void initDataRv(List<VieCoinHistoryModel> list) {
        mDataRv.setHasFixedSize(true);
        mDataRv.setLayoutManager(new LinearLayoutManager(
                this, LinearLayoutManager.VERTICAL, false));
        VieCoinHistoryAdapter historyAdapter = new VieCoinHistoryAdapter(this, list);
        mDataRv.setAdapter(historyAdapter);
    }

    private void initOthers() {
        mNumberTv.setText(String.valueOf(1024));
        mDateTv.setText(SimpleDateFormat.getDateInstance().format(new Date()));
    }
}
